<template>
  <div class="home" :style="{width:width+'px',height: height+'px'}">

    <div  class="home-title"  :style="{width:width+'px',height: 60+'px'}">
        <div class="title-left">
            <div>
              <img src="/static/logo.png">
            </div>

            <div>管理</div>
        </div>
        <div class="title-right">
          <div class="title-right-hidden" v-show="outArea">
            <div class="logout-div"  @click="logout">
              <div class="logout-icon-div">
                <img src="/static/logout.png">
              </div>
              <div class="logout-text">
                退出登录
              </div>
            </div>
          </div>
          <div class="title-right-div1"   @click="hiddenOut">
            <img src="/static/down.png">
          </div>
          <div class="title-right-div2">
            {{userName}}
          </div>
          <div class="title-right-div3">
            <img src="/static/user.png">
          </div>
        </div>
    </div>
    <div class="home-body"   :style="{width:width+'px',height: height-61+'px'}">
      <div class="home-bar"  :style="{width: '200px',height: '100%'}">
        <el-menu default-active="1-0" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">班级管理</span>
            </template>

            <!-- 简单的添加删除 -->
            <el-menu-item index="1-0" @click="navTo('/home/managerAcademy')">学院管理</el-menu-item>
            <el-menu-item index="1-1" @click="navTo('/home/managerClass')">班级管理</el-menu-item>
            <el-menu-item index="1-2" @click="navTo('/home/managerDormitory')">宿舍管理</el-menu-item>
            <el-menu-item index="1-3" @click="navTo('/home/managerGroup')">分组管理</el-menu-item>

          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span slot="title">学生管理</span>
            </template>
            <!-- 设计模糊搜索, 配置修改, 图片上传  -->
            <el-menu-item index="2-1"  @click="navTo('/home/userAdd')">添加学生</el-menu-item>
            <el-menu-item index="2-2"  @click="navTo('/home/userList')">学生列表</el-menu-item>
            <el-menu-item index="2-3"  @click="navTo('/home/userEdit')">修改学生信息</el-menu-item>

          </el-submenu>
<!--          <el-submenu index="3">-->
<!--            <template slot="title">-->
<!--              <i class="el-icon-setting"></i>-->
<!--              <span slot="title">资源传输</span>-->
<!--            </template>-->
<!--            &lt;!&ndash;  扫描同局域网下的后端服务  &ndash;&gt;-->
<!--            <el-menu-item index="3-1">发现设备</el-menu-item>-->
<!--            &lt;!&ndash; 配置对应后端服务器以及对应用户: 测试连接  &ndash;&gt;-->
<!--            <el-menu-item index="3-2">配置连接</el-menu-item>-->
<!--            &lt;!&ndash; 进行资源传输: 前端传到对方后台  &ndash;&gt;-->
<!--            <el-menu-item index="3-3">资源传输</el-menu-item>-->
<!--  语音识别, 语音转文字, 文字转语音, ChatGPT接入  -->
<!--          </el-submenu>-->
        </el-menu>

      </div>
      <div class="home-main"  :style="{width: width-200 + 'px',height: '100%'}">
        <div class="mian-card"  :style="{width: width-250 + 'px',height: height-100+'px'}">

          <transition name="router-fade" mode="out-in">
            <router-view ></router-view>
          </transition>

        </div>
      </div>
    </div>






  </div>
</template>

<script>
  import {getClientSize} from '../util/util';
  // 引入vuex的mapstate映射函数
  import { mapState } from "vuex";

export default {
  mounted(){
    this.width = getClientSize().width;
    this.height = getClientSize().height;
    this.navTo('/home/managerAcademy')
  },
  data(){
    return{
      isCollapse: false, // 用来标记left侧导航窗口的展开和关闭
      userName: "admin",
      outArea: false,
      width: 0,
      height: 0
    }
  },
  computed:{
    // 通过映射, 获得vuex中的state中的参数, 并且把这些参数作为计算属性存在
    // 作为计算属性的好处就是, 计算属性会根据所依赖的属性变化而变化
    ...mapState(['loginStatus', 'userId']),
  },
  methods: {
    hiddenOut(){
      this.outArea = !this.outArea
    },
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    prompt(status, text) {
      var notify = this.$notify({
        title: status,
        message: text
      });

      setTimeout(()=>{
        notify.close()
      }, 1000)
    },
    logout(){
      this.outArea = false
      this.prompt("状态", "即将退出登录")
       // 退出登录方法
      this.$store.dispatch('loginStatus', false)
      setTimeout(() => {
        this.$router.push('/login');
      }, 1000);
    },
    navTo(url){
      this.$router.push(url, ()=>{}, ()=>{});
    }
  }
}
</script>

<style scoped>
.home{
  /*color: white;*/
}
.home-title{
  border-bottom: 1px solid #e6e6e6;
}
.title-left{
  float: left;
  height: 60px;
  width: 300px;
  margin: 0 20px;
  /*background:red;*/
  color: silver;
  /*line-height: 60px;*/
}
.title-left img{
 width: 40px;
 height: 40px;
 margin: 10px;
}
.title-left div{
  float: left;
  height: 60px;
  line-height: 60px;
}
.title-right{
 float: right;
 height: 60px;
 width: 400px;
 margin: 0 20px;

  position: relative;
  top: 0;
}
.title-right-hidden{
  position: absolute;
  right: 0;
  top: 58px;
  width: 120px;
  height: 40px;
  padding: 10px;
  background: white;
  border-radius: 4px;
  box-shadow: 0px 0px 16px 8px rgba(143, 143, 143, 0.22)
}
.logout-div{
  width: 120px;
  height: 40px;
}
.logout-icon-div{
  height: 40px;
  width:40px;
  float: left;

}
.logout-icon-div img{
  height: 20px;
  width: 20px;
  padding: 10px 0 10px 20px;
}
.logout-text{
  height: 40px;
  width: 75px;
  padding-left: 5px;
  line-height: 40px;
  font-size: 14px;
  float: left;
  color: silver;
}
.title-right-div1{
  float: right;
  height: 60px;
  width: 20px;
}
.title-right-div1 img{
  width: 20px;
  height: 20px;
  margin: 20px auto;
}
.title-right-div2{
  float: right;
  height: 60px;
  margin: 0 10px 0 0;
  line-height: 60px;
  color: #acacac;
}
.title-right-div3{
  float: right;
  height: 60px;
}
.title-right-div3 img{
  width: 24px;
  height: 24px;
  margin: 20px 5px 0px 0;
}
.home-body{
 background: silver;
}
.home-bar{
 float: left;
 background: white;
}
.home-main{
 float: left;
 background: #f0f0f0;
}
.mian-card{
 margin: 15px auto;
 background: white;
 border-radius: 10px;
 box-shadow: 2px 4px 4px rgba(0, 0, 0, 0.04);
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
 width: 200px;
 min-height: 400px;
}
</style>
